#ifndef PARAMBASE_H
#define PARAMBASE_H

#include <QObject>
#include <QString>
#include <QDebug>
#include <pthread.h>
#include <QDebug>
#include <unistd.h>
#include <QHostAddress>
#include <QAbstractSocket>
#include <QNetworkInterface>
#include <QNetworkAddressEntry>
#include <QTextCodec>
#include <QUdpSocket>
#include "JsonCheck.h"

#include <QDomComment>
#include "common.h"


//地铁统型 头尾 固定标识
#define TONGXING_MEG_LEN_MIN        9
#define TONGXING_HEAD_OFFSET        0
#define TONGXING_FUNCODE_OFFSET     2
#define TONGXING_DATALEN_OFFSET     4
#define TONGXING_CRC_OFFSET         6
#define TONGXING_DATA_OFFSET        7
//需要加上负载长度
#define TONGXING_TAIL_OFFSET        7


#define TONGXING_HEAD_MAGIC     0xA09F
#define TONGXING_TAIL_MAGIC     0xEFEF

typedef std::pair<int,int>   Pairkey;

enum
{
    TONGXING_SET_LINE        = 0x0001,
    TONGXING_REPORT_STATION  = 0x0002,
    TONGXING_SKIP_STATION    = 0x0003,
    TONGXING_EMERGENCY_MSG   = 0x0004,
    TONGXING_SWITCHSIGNAL    = 0x000A,
    TONGXING_DOOR_ISOLATION  = 0x000F,
    TONGXING_SLEEP_MSG       = 0x0011,
    TONGXING_PREARRIVALTIME  = 0x0012,
    TONGXING_INVALID         = -1,
};

enum
{
    TONGXING_AUDIO_OCC= 0,
    TONGXING_AUDIO_MANUAL,
    TONGXING_AUDIO_EM,
    TONGXING_AUDIO_REPORT,
    TONGXING_AUDIO_MEDIA,
    TONGXING_AUDIO_INVALID = -1,
};

enum
{
    TONGXING_CAR_IN_STATION  = 0x00,
    TONGXING_CAR_WILL_LEAVE  = 0x01,
    TONGXING_CAR_LEAVED_ST   = 0x02,
    TONGXING_CAR_WILL_ARRIVE = 0x03,
    TONGXING_CAR_HAS_ARRIVED = 0x04,
//    TONGXING_WELCOME         = 0xff,
    TONGXING_CAR_INVALID     = -1,
};

enum
{
    TONGXING_RUN_UP         = 0x00,
    TONGXING_RUN_DOWN       = 0x01,
    TONGXING_RUN_INVALID    = -1
};

enum
{
    TONGXING_KEY_POS_NONE       = 0x00,
    TONGXING_KEY_POS_1          = 0x10,
    TONGXING_KEY_POS_6          = 0x01,
    TONGXING_KEY_POS_ALL        = 0x11,
    TONGXING_KEY_POS_INVALID    = -1
};


enum
{
    TONGXING_DOOR_ALL_CLOSE     = 0x00,
    TONGXING_DOOR_LEFT_OPEN     = 0x01,
    TONGXING_DOOR_RIGHT_OPEN    = 0x02,
    TONGXING_DOOR_ALL_OPEN      = 0x03,
    TONGXING_DOOR_INVALID       = -1
};


enum
{
    TONGXING_ST_NORMAL = 0,
    TONGXING_ST_SKIP,
    TONGXING_ST_CROSS,
    TONGXING_ST_INVALID = -1
};

enum
{
    TONGXING_IP_LEFT = 0,
    TONGXING_IP_RIGHT,
    TONGXING_IP_INVALID = -1

};




class ParamBase : public QObject
{
    Q_OBJECT
public:
    explicit ParamBase(QObject *parent = 0);
    ParamBase(const ParamBase&);


    ~ParamBase();

    void UpdateParamBase(const ParamBase&);

    bool IsParamNeedUpdate(const ParamBase&);

    bool IsParamEmergency(const ParamBase&);

    void SetCarHead(int carHead){mCarHead = carHead;}
    int  GetCarHead() const {return mCarHead;}

    void SetCarLoaction(int carLocation){mCarLocation = carLocation;}
    int  GetCarLoaction() const {return mCarLocation;}

    void SetEmergeId(int emerge){mEmerge = emerge;}
    int  GetEmergeId() const {return mEmerge;}

    void SetAudioType(int audioType){mAudioType = audioType;}
    int  GetAudioType() const {return mAudioType;}


    void SetCurTrainHeadNum(int curTrainHeadNum){mCurTrainHeadNum = curTrainHeadNum;}
    int  GetCurTrainHeadNum() const {return mCurTrainHeadNum;}

    void SetStartStationNum(int startStationNum){mStartStationNum = startStationNum;}
    int  GetStartStationNum() const {return mStartStationNum;}

    void SetStopStationNum(int stopStationNum){mStopStationNum = stopStationNum;}
    int  GetStopStationNum() const {return mStopStationNum;}

    void SetCurStationNum(int curStationNum){mCurStationNum = curStationNum;}
    int  GetCurStationNum() const {return mCurStationNum;}

    void SetNextStationNum(int nextStationNum){mNextStationNum = nextStationNum;}
    int  GetNextStationNum() const {return mNextStationNum;}

    void SetCurDoorOpenSide(int openSide){mCurDoorOpenSide = openSide;}
    int  GetCurDoorOpenSide() const {return mCurDoorOpenSide;}

    void SetRunDir(int runDir){mRunDir = runDir;}
    int  GetRunDir() const {return mRunDir;}


    void SetLineId(int lineId){mLineId = lineId;}
    int  GetLineId() const {return mLineId;}

    void SetDevLoaction(int devLocation){mDevLocation = devLocation;}
    int  GetDevLoaction() const {return mDevLocation;}


    void SetDoorIsolation(int doorIsolation){mDoorIsolation = doorIsolation;}
    int  GetDoorIsolation() const {return mDoorIsolation;}


    void SetLoactionIp(const QString& rLocationIp){mLocationIp = rLocationIp;}
    QString  GetLoactionIp() const {return mLocationIp;}

    void SetSkipStation(Pairkey key,QList<int> skipStation){mSkipStation[key] = skipStation;}
    //void SetSkipStation(QList<int>& rSkipStation){mSkipStation = rSkipStation;}
     void SetSkipStation(QMap<Pairkey,QList<int>> skipStation){mSkipStation = skipStation;}
    QMap<Pairkey,QList<int>> GetSkipStation() const {return mSkipStation;}
    //QList<int>&  GetSkipStation()  {return mSkipStation;}


    const QString GetLocalIp(const QString&);
    void CalCurDevLocation();


    void SetXmlDomEle(QDomElement *pXmlDomEle)
    {

        if(NULL != mpXmlDomEle )
        {
            delete mpXmlDomEle;
            mpXmlDomEle = NULL;
        }

        mpXmlDomEle = pXmlDomEle;
    }


    QDomElement* GetXmlDomEle()const {return mpXmlDomEle;}


    void SetCheckScreenMode(const bool mode){mIsCheckScreenMode = mode;}
    bool IsCheckScreenMode() const {return mIsCheckScreenMode;}

private:
    int mAudioType;

    int mEmerge;

    int mCarHead;

    int mCarLocation;

    int mCurTrainHeadNum;

    int mStartStationNum;

    int mStopStationNum;

    int mCurStationNum;

    int mNextStationNum;

    int mCurDoorOpenSide;

    int mRunDir;

    int mLineId;

    int mDevLocation;

    int mDoorIsolation;

    QString mLocationIp;

    //越战编号
    QMap<Pairkey,QList<int>> mSkipStation;

    //XML 格式的配置信息
    QDomElement* mpXmlDomEle;

    bool mIsCheckScreenMode;
};

#endif // PARAMBASE_H
